package com.zkingsoft.services.lin.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zkingsoft.dao.lin.LinOrderDetailsDao;
import com.zkingsoft.exception.GlobleException;
import com.zkingsoft.model.lin.LinOrderDetails;
import com.zkingsoft.pojo.PaginationVO;
import com.zkingsoft.services.lin.LinOrderDetailsService;
import com.zkingsoft.util.ModelUtils;

/**
 * This field was generated by Zking.software.Codegen.
 * 
 * @date 2017-05-08 15:14
 */
@Service("linOrderDetailsService")
public class LinOrderDetailsServiceImpl implements LinOrderDetailsService {

	@Autowired
	private LinOrderDetailsDao linOrderDetailsDao;

	@Override
	public int add(LinOrderDetails linOrderDetails) {

		return linOrderDetailsDao.insert(linOrderDetails);

	}

	@Override
	public int batchAdd(List<LinOrderDetails> linOrderDetailsList) {
		int num = 0;

		int c = 10000;
		int size = linOrderDetailsList.size() / c + 1;
		for (int i = 0; i < size; i++) {
			int begin = i * c;
			int end = (i + 1) * c;
			end = end >= linOrderDetailsList.size() ? linOrderDetailsList
					.size() : end;
			List<LinOrderDetails> insertList = linOrderDetailsList.subList(
					begin, end);
			num += linOrderDetailsDao.batchInsert(insertList);
		}
		return num;

	}

	@Override
	public int modifyByMap(LinOrderDetails oldLinOrderDetails,
			LinOrderDetails newLinOrderDetails) {

		if (!ModelUtils.isModified(oldLinOrderDetails, newLinOrderDetails)) {
			return 1;
		}
		Map<String, Object> modifyMap = null;
		try {
			modifyMap = ModelUtils.comparePojo2Map(oldLinOrderDetails,
					newLinOrderDetails);
		} catch (Exception e) {
			throw new GlobleException("数据对比失败");
		}
		if (modifyMap.size() > 0) {
			modifyMap.put("detailsId", oldLinOrderDetails.getDetailsId());
			linOrderDetailsDao.updateByMap(modifyMap);
		}
		return 1;
	}

	@Override
	public int modifyByModel(LinOrderDetails linOrderDetails) {

		return linOrderDetailsDao.updateByModel(linOrderDetails);

	}

	@Override
	public int remove(List<Long> list) {

		return linOrderDetailsDao.deleteByIds(list);

	}

	@Override
	public int removeById(Long detailsId) {

		return linOrderDetailsDao.deleteById(detailsId);

	}

	@Override
	public int removeByModel(LinOrderDetails linOrderDetails) {

		return linOrderDetailsDao.deleteByModel(linOrderDetails);

	}

	@Override
	public List<LinOrderDetails> findInPage(LinOrderDetails linOrderDetails,
			PaginationVO pageVo) {

		return linOrderDetailsDao.selectInPage(linOrderDetails, pageVo);

	}

	@Override
	public List<LinOrderDetails> findByModel(LinOrderDetails linOrderDetails) {

		return linOrderDetailsDao.selectByModel(linOrderDetails);

	}

	@Override
	public int findTotal(LinOrderDetails linOrderDetails) {

		return linOrderDetailsDao.selectTotalRecord(linOrderDetails);

	}

	@Override
	public LinOrderDetails findById(Long detailsId) {

		return linOrderDetailsDao.selectById(detailsId);

	}

	@Override
	public List<LinOrderDetails> getOrderDetails(Long orderId,
			PaginationVO pageVo) {

		return linOrderDetailsDao.getOrderDetails(orderId, pageVo);
	}

	@Override
	public int getOrderDetailsTotal(Long orderId) {

		return linOrderDetailsDao.getOrderDetailsTotal(orderId);
	}

}